import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';
import 'state.dart';

class ServerUrlFormPage extends StatefulWidget {
  const ServerUrlFormPage({Key? key}) : super(key: key);

  @override
  State<ServerUrlFormPage> createState() => _ServerUrlFormPageState();
}

class _ServerUrlFormPageState extends State<ServerUrlFormPage> {
  final ServerUrlFormController controller = Get.put(ServerUrlFormController());
  final ServerUrlFormState state = Get.find<ServerUrlFormController>().state;

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar: TDNavBar(
        title: '服务地址设置',
      ),
      body: Column(
        children: [
          TDInput(
            controller: controller.nameController,
            required: true,
            leftLabel: '名称',
            type: TDInputType.special,
            textAlign: TextAlign.end,
            backgroundColor: Colors.transparent,
            hintText: '请输入名称',
            inputType: TextInputType.name,
          ),
          TDInput(
            controller: controller.serverUrlController,
            required: true,
            leftLabel: '服务地址',
            type: TDInputType.special,
            textAlign: TextAlign.end,
            backgroundColor: Colors.transparent,
            hintText: '请输入服务地址',
            inputType: TextInputType.url,
          ),
          TDInput(
            controller: controller.intercomUrlController,
            required: true,
            maxLength: 11,
            leftLabel: '对讲IP',
            type: TDInputType.special,
            textAlign: TextAlign.end,
            backgroundColor: Colors.transparent,
            hintText: '请输入对讲IP',
            inputType: TextInputType.number,
          ),
          Gaps.vGap12,
          TDButton(
            text: '保存',
            onTap: controller.save,
            theme: TDButtonTheme.primary,
            isBlock: true,
          )
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<ServerUrlFormController>();
    super.dispose();
  }
}